import { DeviceStatus } from '../../../constants/device';
import { UpgradeStatus } from '../../../constants/upgrade';

/**
 * 校验表单信息是否合法
 * @param {object} form 表单信息
 */
export function validateForm(form) {
  if (!form.serialNumber) return '请填写产品序列号';
  if (!form.typeUuid) return '请填写产品类型';
}

/**生成设备状态别下拉列表可选数据*/
export function generateSelectorData() {
  const result = [{ value: '', label: '全部' }];
  Object.values(DeviceStatus).forEach(status => {
    result.push({ value: status, label: getDisplay(status) });
  });
  return result;
}

/**
 * 获取设备状态显示内容
 * @param {string} status 设备状态
 */
export function getDisplay(status) {
  switch (status) {
    case DeviceStatus.Unknown:
      return '未知';
    case DeviceStatus.Normal:
      return '正常/在线';
    case DeviceStatus.Abnormal:
      return '告警';
    case DeviceStatus.OnCheck:
      return '临检';
    case DeviceStatus.Offline:
      return '离线';
    default:
      return '未知级别';
  }
}

/**生成设备状态别下拉列表可选数据*/
export function upgradeSelectorData() {
  const result = [{ value: '', label: '升级状态' }];
  Object.values(UpgradeStatus).forEach(status => {
    result.push({ value: status, label: getUpgradeDisplay(status) });
  });
  return result;
}

/**
 * 获取升级状态显示内容
 * @param {string} status 升级状态
 */
export function getUpgradeDisplay(status) {
  switch (status) {
    case UpgradeStatus.Unknown:
      return '未知';
    case UpgradeStatus.ToUpgrade:
      return '待升级';
    case UpgradeStatus.Upgraded:
      return '已升级';
    case UpgradeStatus.Disabled:
      return '已禁用';
    default:
      return '未知级别';
  }
}
